package com.ruoyi.system.controller;

import java.util.Arrays;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.system.domain.Precords;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Cstandard;
import com.ruoyi.system.service.ICstandardService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 收费标准Controller
 *
 * @author ruoyi
 * @date 2023-10-20
 */
@RestController
@RequestMapping("/system/cstandard")
public class CstandardController extends BaseController
{
    @Autowired
    private ICstandardService cstandardService;

    /**
     * 查询收费标准列表
     */
    @PreAuthorize("@ss.hasPermi('system:cstandard:list')")
    @GetMapping("/list")
    public TableDataInfo list(Cstandard cstandard)
    {
        startPage();
        QueryWrapper<Cstandard> queryWrapper=new QueryWrapper<>();
        if(cstandard.getCartype()!=null&&!"".equals(cstandard.getCartype())){
            queryWrapper.like("cartype",cstandard.getCartype());
        }
        List<Cstandard> list = cstandardService.list(queryWrapper);
        return getDataTable(list);
    }

    /**
     * 导出收费标准列表
     */
    @PreAuthorize("@ss.hasPermi('system:cstandard:export')")
    @Log(title = "收费标准", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Cstandard cstandard)
    {
        QueryWrapper<Cstandard> queryWrapper=new QueryWrapper<>();
        if(cstandard.getCartype()!=null&&!"".equals(cstandard.getCartype())){
            queryWrapper.like("cartype",cstandard.getCartype());
        }
        List<Cstandard> list = cstandardService.list(queryWrapper);
        ExcelUtil<Cstandard> util = new ExcelUtil<Cstandard>(Cstandard.class);
        util.exportExcel(response, list, "收费标准数据");
    }

    /**
     * 获取收费标准详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:cstandard:query')")
    @GetMapping(value = "/{cid}")
    public AjaxResult getInfo(@PathVariable("cid") Long cid)
    {
        return success(cstandardService.getById(cid));
    }

    /**
     * 新增收费标准
     */
    @PreAuthorize("@ss.hasPermi('system:cstandard:add')")
    @Log(title = "收费标准", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Cstandard cstandard)
    {
        return toAjax(cstandardService.save(cstandard));
    }

    /**
     * 修改收费标准
     */
    @PreAuthorize("@ss.hasPermi('system:cstandard:edit')")
    @Log(title = "收费标准", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Cstandard cstandard)
    {
        return toAjax(cstandardService.updateById(cstandard));
    }

    /**
     * 删除收费标准
     */
    @PreAuthorize("@ss.hasPermi('system:cstandard:remove')")
    @Log(title = "收费标准", businessType = BusinessType.DELETE)
    @DeleteMapping("/{cids}")
    public AjaxResult remove(@PathVariable Long[] cids)
    {
        return toAjax(cstandardService.removeByIds(Arrays.asList(cids)));
    }
}
